using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace OnlineAnadolu
{
    public partial class Admin_icin_Kullanici_Listesi : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SqlDataSource1.SelectCommand = "SELECT users.firstname, users.gender, users.lastvisit, users.user_name, contact.phone, contact.phone2, contact.email, address.addressline1, address.addressline2, states.statename, locals.localname FROM states INNER JOIN users INNER JOIN contact ON users.contactid = contact.contactinfoid INNER JOIN address ON users.addressid = address.addressid INNER JOIN department ON users.departmentid = department.departmentid ON states.pkid = address.stateid INNER JOIN locals ON address.localid = locals.fkid";
               
            }
            if (Session["usertype"].ToString() != "1")
            {
                Response.Redirect("HataSayfasi.aspx");
            }
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
          
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
           
            Database db = new Database();
            string bul = "Select enduserid from users where user_name=N'" + GridView1.Rows[GridView1.SelectedIndex].Cells[3].Text + "'";
            DataTable dt = new DataTable();
            dt = db.select(bul);
            foreach (DataRow dr in dt.Rows)
            {
                bul = dr["enduserid"].ToString();
            }
            string sil = "Delete  From users where user_name=N'" + GridView1.Rows[GridView1.SelectedIndex].Cells[3].Text + "'";
            db.insert(sil);
            string silprod = "Delete From products where userid='"+bul+"'";
            db.insert(silprod);
            GridView1.DataBind();
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            SqlDataSource1.SelectCommand = "SELECT users.firstname, users.gender, users.lastvisit, users.user_name, contact.phone, contact.phone2, contact.email, address.addressline1, address.addressline2, states.statename, locals.localname FROM states INNER JOIN users INNER JOIN contact ON users.contactid = contact.contactinfoid INNER JOIN address ON users.addressid = address.addressid INNER JOIN department ON users.departmentid = department.departmentid ON states.pkid = address.stateid INNER JOIN locals ON address.localid = locals.fkid where(users.firstname like  '%" + tb_Anahtar.Text + "%' or  users.user_name like '%" + tb_Anahtar.Text + "%' or address.addressline1 like '%" + tb_Anahtar.Text + "%' or states.statename like '%" + tb_Anahtar.Text + "%' or locals.localname like '%" + tb_Anahtar.Text + "%')";
      
        }
    }
}
